<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input @keyup.enter.native="handleFilter" style="width: 200px;" class="filter-item" placeholder="用户" v-model="listQuery.f_lk_userId"></el-input>
      <el-input @keyup.enter.native="handleFilter" style="width: 200px;" class="filter-item" placeholder="操作类型" v-model="listQuery.f_lk_operation"></el-input>
      <el-date-picker v-model="listQuery.f_ge_time" type="datetime" placeholder="起始时间"></el-date-picker>
      <el-date-picker v-model="listQuery.f_le_time" type="datetime" placeholder="终止时间"></el-date-picker>
      <el-button class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">搜索</el-button>
      <el-button class="filter-item" type="success" icon="el-icon-search" @click="resetFiler">重置</el-button>
    </div>

    <el-table :data="list" v-loading.body="listLoading" element-loading-text="数据正在加载中，请稍后..." border fit highlight-current-row>
      <el-table-column label="时间" width="200" align="left">
        <template slot-scope="scope">
          <span>{{scope.row.time}}</span>
        </template>
      </el-table-column>
      <el-table-column label='用户' align="left">
        <template slot-scope="scope">
          {{scope.row.userId}}
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          {{scope.row.operation}}
        </template>
      </el-table-column>
      <el-table-column label="内容" align="left">
        <template slot-scope="scope">
          {{scope.row.content}}
        </template>
      </el-table-column>
      <!--
      <el-table-column label="操作" width="100" align="center">
        <template slot-scope="scope">
          <span>删除</span>
        </template>
      </el-table-column>
      -->
    </el-table>

    <div v-show="!listLoading" class="pagination-container">
      <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="listQuery.page"
                     :page-sizes="[10,20,30,50]" :page-size="listQuery.size" layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { getUserLogList } from '@/api/user'

export default {
  data() {
    return {
      list: null,
      listLoading: true,
      total: null,
      listQuery: {
        page: 1,
        size: 20,
        f_lk_userId: undefined,
        f_lk_operation: undefined,
        f_ge_time: undefined,
        f_le_time: undefined,
        sort: '+id'
      }
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      this.listLoading = true
      getUserLogList(this.listQuery).then(response => {
        this.list = response.data
        this.total = response.total
        this.listLoading = false
      }).catch(() => {
        this.listLoading = false
      })
    },
    handleFilter() {
      this.listQuery.page = 1
      this.fetchData()
    },
    resetFiler() {
      this.listQuery = {}
      this.listQuery.page = 1
      this.listQuery.size = 20
      this.fetchData()
    },
    handleSizeChange(val) {
      this.listQuery.size = val
      this.fetchData()
    },
    handleCurrentChange(val) {
      this.listQuery.page = val
      this.fetchData()
    }
  }
}
</script>
